package com.qf.blog.controller;

import com.qf.blog.dto.IndexPostDto;
import com.qf.blog.service.IPostService;
import com.qf.blog.service.impl.AdminService;
import com.qf.blog.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private IPostService postService;

    @GetMapping("/postList")
    public String postList(Model model) {
        List<IndexPostDto> postDtoList = adminService.postList();
        model.addAttribute("postDtoList", postDtoList);
        return "admin/postList";
    }

    @PostMapping("/updatePostType")
    @ResponseBody
    public Result updatePostType(@RequestBody Map<String, Object> param) {
        Integer id = (Integer) param.get("id");
        Integer type = (Integer) param.get("type");
        Integer status = postService.updatePostType(id, type);
        return Result.ok();
    }
}
